/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.business.coupon.core.domain;

import cn.hutool.core.lang.Assert;
import info.peigen.hotpot.business.coupon.facade.enums.CouponReceiveFrequencyType;
import info.peigen.hotpot.common.core.result.ResultCode;
import info.peigen.hotpot.common.service.base.exception.BusinessException;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import lombok.experimental.FieldDefaults;
import lombok.experimental.SuperBuilder;

/**
 * <b>(CouponReceiveFrequency)</b>
 * 优惠券领取频次
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2022/6/28
 */
@SuperBuilder
@Data
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
@Accessors(chain = true)
public class CouponReceiveFrequency {
    CouponReceiveFrequencyType type;
    int                        count;

    public void check() {
        if (type == CouponReceiveFrequencyType.Times) {
            // TODO peigen 按次检查需要统计当前客户是否还有此优惠券未用完
        }

        // 总量控制
        Assert.isTrue(count >= 3, () -> new BusinessException(ResultCode.FAILURE, "数量不得大于叁!"));
    }
}